using Godot;

namespace GoGameClient.script.node.world;

public partial class BloodControl : Control
{
    // Called when the node enters the scene tree for the first time.
    private Range _hpBar;
    private Range _bloodBar;
    private Range _mpBar;
    private Range _angerBar;
    private Range _expBar;
    private TextureButton _avator;

    private Range _petHpBar;
    private Range _petMpBar;
    private Range _petExpBar;
    private TextureButton _petAvator;

    private int _maxHp;
    private int _blood;
    private int _currentHp;

    private int _maxMp;
    private int _currentMp;

    private int _maxAnger = 150;
    private int _anger;

    private long _maxExp;
    private long _exp;


    private int _petMaxHp;
    private int _petCurrentHp;

    private int _petMaxMp;
    private int _petCurrentMp;

    private long _petMaxExp;
    private long _petExp;


    public void SetMaxHp(int max)
    {
        _maxHp = max;
    }

    public void SetBlood(int blood)
    {
        _blood = blood;
    }

    public void SetCurrentHp(int current)
    {
        _currentHp = current;
    }


    public void SetMaxMp(int max)
    {
        _maxMp = max;
    }

    public void SetCurrentMp(int current)
    {
        _currentMp = current;
    }


    public void SetAnger(int anger)
    {
        _anger = anger;
    }

    public void SetMaxExp(long max)
    {
        _maxExp = max;
    }

    public void SetExp(long exp)
    {
        _exp = exp;
    }


    public void SetPetMaxHp(int max)
    {
        _petMaxHp = max;
    }

    public void SetPetCurrentHp(int current)
    {
        _petCurrentHp = current;
    }

    public void SetPetMaxMp(int max)
    {
        _petMaxMp = max;
    }

    public void SetPetCurrentMp(int current)
    {
        _petCurrentMp = current;
    }

    public void SetPetMaxExp(long max)
    {
        _petMaxExp = max;
    }

    public void SetPetExp(long exp)
    {
        _petExp = exp;
    }


    public void RefreshRole()
    {
        _hpBar.MaxValue = _maxHp;
        _hpBar.MinValue = 0;
        _hpBar.Value = _currentHp;

        _bloodBar.MaxValue = _maxHp;
        _bloodBar.MinValue = 0;
        _bloodBar.Value = _blood;

        _mpBar.MaxValue = _maxMp;
        _mpBar.MinValue = 0;
        _mpBar.Value = _currentMp;

        _angerBar.MaxValue = _maxAnger;
        _angerBar.MinValue = 0;
        _angerBar.Value = _anger;

        _expBar.MaxValue = _maxExp;
        _expBar.MinValue = 0;
        _expBar.Value = _exp;
    }


    public void SetAvator(Texture2D texture)
    {
        _avator.TextureNormal = texture;
    }

    public void SetPetAvator(Texture2D texture)
    {
        _petAvator.TextureNormal = texture;
    }

    private void PetAvatorButtonDown()
    {
        _petAvator.Position = new Vector2(_petAvator.Position.X + 1, _petAvator.Position.Y + 1);
    }


    private void PetAvatorButtonUp()
    {
        _petAvator.Position = new Vector2(_petAvator.Position.X - 1, _petAvator.Position.Y - 1);
    }

    private void AvatorButtonDown()
    {
        _avator.Position = new Vector2(_avator.Position.X + 2, _avator.Position.Y + 2);
    }


    private void AvatorButtonUp()
    {
        _avator.Position = new Vector2(_avator.Position.X - 2, _avator.Position.Y - 2);
    }

    private void AvatorButtonPressed()
    {
        GD.Print("AvatorButtonPressed");
    }

    private void PetAvatorButtonPressed()
    {
        GD.Print("PetAvatorButtonPressed");
    }


    public void RefreshPet()
    {
        _petHpBar.MaxValue = _petMaxHp;
        _petHpBar.MinValue = 0;
        _petHpBar.Value = _petCurrentHp;

        _petMpBar.MaxValue = _petMaxMp;
        _petMpBar.MinValue = 0;
        _petMpBar.Value = _petCurrentMp;

        _petExpBar.MaxValue = _petMaxExp;
        _petExpBar.MinValue = 0;
        _petExpBar.Value = _petExp;
    }


    public override void _Ready()
    {
        _hpBar = GetNode<Range>("HpProgressBar");
        _bloodBar = GetNode<Range>("BloodProgressBar");
        _mpBar = GetNode<Range>("MpProgressBar");
        _angerBar = GetNode<Range>("AngerProgressBar");
        _expBar = GetNode<Range>("ExpProgressBar");
        _avator = GetNode<TextureButton>("Avator");

        _petHpBar = GetNode<Range>("PetHpProgressBar");
        _petMpBar = GetNode<Range>("PetMpProgressBar");
        _petExpBar = GetNode<Range>("PetExpProgressBar");
        _petAvator = GetNode<TextureButton>("PetAvator");
    }
}